
/*This do file generates the estimation samples for Table 2, Columns 3 to 6. 
 Initial sample includes US-born individuals from ACS 2009 and 2018 with birth cohorts 1964 to 1976 */
clear all
set matsize 10000
set maxvar 40000
set more off
global data " "
global dir " "
use $data/acs_2009_2018_main.dta, clear


*Keep women only
keep if sex==2
*Race/Ethnicity
g hisp = (hispan>0)
	g white = (race==1)&!hisp
	g black = ((race==2)|inrange(raced,830,845))&!hisp 
*education--high school or more.
keep if educd>=62

*division
gen division=.
replace division=1 if mom_birth_state==9|mom_birth_state==23|mom_birth_state==25|mom_birth_state==33|mom_birth_state==44|mom_birth_state==50
replace division=2 if mom_birth_state==34|mom_birth_state==36|mom_birth_state==42
replace division=3 if mom_birth_state==18|mom_birth_state==17|mom_birth_state==26|mom_birth_state==39|mom_birth_state==55
replace division=4 if mom_birth_state==19|mom_birth_state==20|mom_birth_state==27|mom_birth_state==29|mom_birth_state==31|mom_birth_state==38|mom_birth_state==46
replace division=5 if mom_birth_state==10|mom_birth_state==11|mom_birth_state==12|mom_birth_state==13|mom_birth_state==24|mom_birth_state==37|mom_birth_state==45 |mom_birth_state==51|mom_birth_state==54
replace division=6 if mom_birth_state==1|mom_birth_state==21|mom_birth_state==28|mom_birth_state==47
replace division=7 if mom_birth_state==5|mom_birth_state==22|mom_birth_state==40|mom_birth_state==48
replace division=8 if mom_birth_state==4|mom_birth_state==8|mom_birth_state==16|mom_birth_state==35|mom_birth_state==30|mom_birth_state==49|mom_birth_state==32|mom_birth_state==56
replace division=9 if mom_birth_state==2|mom_birth_state==6|mom_birth_state==15|mom_birth_state==41|mom_birth_state==53

*age categories
gen age_cat=.
replace age_cat=1 if age<20
replace age_cat=2 if age>=20&age<=24
replace age_cat=3 if age>=25&age<=34
replace age_cat=4 if age>=35

*childlessness
gen childlessness=0
replace childlessness=1 if nchild==0

*keeping ~45 year-olds
gen age45=0
replace age45=1 if age==45&by<=1973

gen age44=0
replace age44=1 if age==44&by==1974

gen age43=0
replace age43=1 if age==43&by==1975

gen age42=0
replace age42=1 if age==42&by==1976

keep if age45==1|age44==1|age43==1|age42==1
drop age45  age44 age43 age42

gen plus0=0
replace plus0=1 if index==0
gen plus1=0
replace plus1=1 if index==1
gen plus2=0
replace plus2=1 if index==2
gen plus3=0
replace plus3=1 if index==3
gen plus4=0
replace plus4=1 if index>=4


gen minus1=0
replace minus1=1 if index==-1
gen minus2=0
replace minus2=1 if index==-2
gen minus3=0
replace minus3=1 if index==-3
gen minus4=0
replace minus4=1 if index==-4
gen minus5=0
replace minus5=1 if index<=-5


*generate black and white estimation samples
preserve
keep if black==1 
save black_fertility_09_18.dta, replace
restore

preserve
keep if white==1 
save white_fertility_09_18.dta, replace
restore
